#include "StdAfx.h"
#include "TG_SvrNetSDK.h"

#include "TGSvrNetMan.h"

UINT32 __stdcall TG_SvrNet_GetSdkVersion()
{
	return 0;
}

TGERR_CODE __stdcall TG_SvrNet_Init(TGHANDLE &hSvrNet)
{
	TGSvrNetMan *pSvrNet = new TGSvrNetMan();
	if( NULL == pSvrNet )
	{
		return TG_ERR_FAILURE;
	}

    hSvrNet = (TGHANDLE)pSvrNet;

	return TG_ERR_SUCCESS;
}

TGERR_CODE __stdcall TG_SvrNet_Cleanup(TGHANDLE hSvrNet)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	delete pSvrNet;
	pSvrNet = NULL;

	return TG_ERR_SUCCESS;
}

TGERR_CODE __stdcall TG_SvrNet_SetConnectTime(TGHANDLE hSvrNet,UINT32 nWaitTime, UINT32 nTryTimes)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->SetConnectTime(nWaitTime,nTryTimes);
}

TGERR_CODE __stdcall TG_SvrNet_SetListen(TGHANDLE hSvrNet,SINT8 *pszIP,UINT16 nCmdPort, UINT16 nDataPort)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->SetListen(pszIP,nCmdPort,nDataPort);
}



TGERR_CODE __stdcall TG_SvrNet_RegCheckUserCallBack(TGHANDLE hSvrNet,SvrNetCheckUserCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegCheckUserCallBack(funCallBack,pContext);
}



TGERR_CODE __stdcall TG_SvrNet_RegSetConfigCallBack(TGHANDLE hSvrNet,SvrNetSetConfigCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegSetConfigCallBack(funCallBack,pContext);
}

TGERR_CODE __stdcall TG_SvrNet_RegGetConfigCallBack(TGHANDLE hSvrNet,SvrNetGetConfigCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegGetConfigCallBack(funCallBack,pContext);
}


TGERR_CODE __stdcall TG_SvrNet_RegRealStreamCallBack(TGHANDLE hSvrNet,SvrNetRealStreamCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegRealStreamCallBack(funCallBack,pContext);
}

TGERR_CODE __stdcall TG_SvrNet_RegRealStreamItemCallBack(TGHANDLE hSvrNet,SvrNetRealStreamItemCBFun funCallBack,VOID *pContext)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->RegRealStreamItemCallBack(funCallBack,pContext);
}



TGERR_CODE __stdcall TG_SvrNet_Start(TGHANDLE hSvrNet)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->SvrStart();
}

TGERR_CODE __stdcall TG_SvrNet_Stop(TGHANDLE hSvrNet)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->SvrStop();
}


TGERR_CODE __stdcall TG_SvrNet_RemoveCamera(TGHANDLE hSvrNet,TG_DEV_INFO *pDevInfo)
{
	TGSvrNetMan *pSvrNet = (TGSvrNetMan *)hSvrNet;
	if( NULL == pSvrNet )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pSvrNet->m_xRealStreamMan.RemoveCamera(pDevInfo);
}

TGERR_CODE __stdcall TG_SvrNet_RemoveCameraItem(TGHANDLE hCamera,TGHANDLE hItem)
{
	SvrNetRPCamera *pCamera = (SvrNetRPCamera*)hCamera;
	if( NULL == pCamera )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pCamera->RemoveItem(hItem);
}

TGERR_CODE __stdcall TG_SvrNet_GetCameraItemCount(TGHANDLE hCamera,UINT32 &nCount)
{
	SvrNetRPCamera *pCamera = (SvrNetRPCamera*)hCamera;
	if( NULL == pCamera )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pCamera->GetItemCount(nCount);
}


TGERR_CODE __stdcall TG_SvrNet_SetRealStreamFrame(TGHANDLE hCamera,VOID *pFrame,UINT32 lFrameSize)
{
	SvrNetRPCamera *pCamera = (SvrNetRPCamera*)hCamera;
	if( NULL == pCamera )
	{
		return TG_ERR_PARAMETER_ERROR;
	}

	return (TGERR_CODE)pCamera->SetFrame(pFrame,lFrameSize);
}
